$(function(){
	formComment();
});

function formComment() {
            var form2 = $('#form_sample_2');
            var error2 = $('.alert-danger', form2);
            var success2 = $('.alert-success', form2);

            form2.validate({
                errorElement: 'span', //default input error message container
                errorClass: 'help-block', // default input error message class
                focusInvalid: false, // do not focus the last invalid input
                ignore: "",
                rules: {
                	oldPassword: {
                        minlength: 6,
                        required: true
                    },
                    newPassword: {
                        required: true,
                        minlength: 6
                    },
                    rePassword: {
                        required: true,
                        minlength: 6,
                        equalTo:'#newPassword'
                    }
                },
                messages: {
                	oldPassword: {
                		minlength:'原密码最少为6位',
                        required:'原始密码不能为空'
                    },
                    newPassword: {
                    	required:'新密码不能为空',
                    	minlength:'新密码至少为6位'
                    },
                    rePassword: {
                    	required:'确认密码不能为空',
                    	minlength:'确认密码至少6位',
                    	equalTo:'两次输入密码不一致'
                    }
                },
                invalidHandler: function (event, validator) { //display error alert on form submit              
                    success2.hide();
                    error2.show();
                    App.scrollTo(error2, -200);
                },

                errorPlacement: function (error, element) { // render error placement for each input type
                    var icon = $(element).parent('.input-icon').children('i');
                    icon.removeClass('fa-check').addClass("fa-warning");  
                    icon.attr("data-original-title", error.text()).tooltip({'container': 'body'});
                },

                highlight: function (element) { // hightlight error inputs
                    $(element)
                        .closest('.form-group').addClass('has-error'); // set error class to the control group   
                },

                unhighlight: function (element) { // revert the change done by hightlight
                    
                },

                success: function (label, element) {
                    var icon = $(element).parent('.input-icon').children('i');
                    $(element).closest('.form-group').removeClass('has-error').addClass('has-success'); // set success class to the control group
                    icon.removeClass("fa-warning").addClass("fa-check");
                },

                submitHandler: function (form) {
                    success2.show();
                    error2.hide();
                    var params=form2.serialize();  
                    if(params!=null){
                    	$.ajax({
                    		url:'web/updatePwd.htm',
                    		data:params,
                    		type:'post',
                    		success:function(data){
                    			alert(data.message);
                    			if(data.success){
                    				//这里执行跳出系统
                    				location.href="web/loginOut.htm";
                    			}
                    		}
                    	});
                    }
                }
                
            });


}             